﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Bussiness;
using System.Data;
using Truextend.CoffeShop.Service;

namespace Truextend.CoffeShop.Presenter.InternalCoffeShop
{
    public class InternalCoffeeShopPresenter
    {
        IInternalCoffeeShop view;

        public InternalCoffeeShopPresenter(IInternalCoffeeShop view) {
            this.view = view;
        }


        public void FillProducts()
        {
            ProductService service = new ProductService();

            IList<Model.Product> listProducts = service.GetAllInternalProducts();

            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("ProductID");
            dataTable.Columns.Add("Product");
            dataTable.Columns.Add("Price");
            dataTable.Columns.Add("Amount");
            dataTable.Columns.Add("TotalPrice");

            foreach(var product in listProducts){

                DataRow dataRow = dataTable.NewRow();
                dataRow["ProductID"] = product.ProductId;
                dataRow["Product"] = product.Name;
                dataRow["Price"] = product.Price;
                dataRow["Amount"] = 1;
                dataRow["TotalPrice"] = product.Price;

                dataTable.Rows.Add(dataRow);
            }

            view.products = dataTable;
        }

        public void AddConsumption(string productId)
        {
            ConsumptionService service = new ConsumptionService();

            Model.Consumption consumption = new Model.Consumption() 
            { 
                UserId = view.userId,
                UserName = view.userName,
                Price = view.totalPrice,
                Quantity = view.amount,
                State = "NTCON"
            };

            service.AddConsumptionByInternalProducts(int.Parse(productId),consumption);
        }
    }
}
